package com.zzptc.sw.myappmiaobiao1;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.widget.Button;
import android.widget.Chronometer;
import android.widget.TextView;
import android.widget.Toast;


public class MainActivity extends AppCompatActivity  implements View.OnClickListener, Chronometer.OnChronometerTickListener  {
  private   Chronometer main_ch_time;
  private   Button main_bt_kqmb,main_bt_gbmb,main_bt_tzmb;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();

    }

    private void initView() {
        main_ch_time = findViewById(R.id.main_ch_time);
        main_bt_kqmb = findViewById(R.id.main_bt_kqmb);
        main_bt_gbmb = findViewById(R.id.main_bt_gbmb);
        main_bt_tzmb = findViewById(R.id.main_bt_tzmb);
        main_ch_time.setOnChronometerTickListener(this);
        main_bt_kqmb.setOnClickListener(this);
        main_bt_tzmb.setOnClickListener(this);
        main_bt_gbmb.setOnClickListener(this);
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.main_bt_kqmb:
                main_ch_time.start();//开始
                break;
            case R.id.main_bt_gbmb:
                main_ch_time.setBase(SystemClock.elapsedRealtime());//去掉过去时间？？
                break;
            case R.id.main_bt_tzmb:
                main_ch_time.stop();//结束
                break;
        }
    }

  //结束时间 关闭 直接到0 ;
    @Override
    public void onChronometerTick(Chronometer chronometer) {
        String s = main_ch_time.getText().toString();
        if (s.equals("00:00")){
            Toast.makeText(MainActivity.this,"时间到了下班了，靓仔！",Toast.LENGTH_SHORT).show();
        }
    }
}